

public class DisplayGrid {

	/*
       This program shows a window full of randomly colored
       squares.  A "disturbance" moves randomly around
       in the window, randomly changing the color of
       each square that it visits.  The program runs
       in an infinite loop, and so will never end on its
       own.
	 */

	int rows;    // number of rows of squares
	// (The rows of squares are numbered from 0 to ROWS-1)
	int columns; // number of columns of squares
	// (The columns of squares are numbered from 0 to COLUMNS-1)

	MosaicFrame mosaic;   // the actual window
	int currentRow; // row currently containing the disturbance
	int currentColumn; // column currently containing disturbance
	int[][] colors;
	public DisplayGrid(int rws, int clmns, String name) {
		// Main program creates the window, fills it with
		// random colors, then moves the disturbance in
		// a random walk around the window.
		colors = new int[][] {{255,255,255}, {0,0,0}};
		rows = rws;
		columns = clmns;
		mosaic = new MosaicFrame(rows,columns,10,7,name);
	}  // end of main()


	void updateDisplaly(int rowNum, int colNum) {
		// change the square in row number rowNum and
		// column number colNum to a random color.
		int red = (int)(256*Math.random());    // choose random levels in range
		int green = (int)(256*Math.random());  //     0 to 255 for red, green, 
		int blue = (int)(256*Math.random());   //     and blue color components
		mosaic.setColor(rowNum,colNum,red,green,blue);  
	}  // end of changeToRandomColor()

	void updateDisplaly(int [][] items) {
		for(int i=0; i<items.length; i++)
		{
			for (int j=0; j<items[i].length;j++)
			{
				mosaic.setColor(j,i,colors[items[i][j]][0],colors[items[i][j]][1],colors[items[i][j]][2]); 
			}
		}
		mosaic.repaint();
	}  // end of changeToRandomColor()

} // end of class RandomMosaicWalk


